package com.cbgolf.oa.model;

import android.support.v4.util.ArrayMap;
import com.cbgolf.oa.base.BaseModel;
import com.cbgolf.oa.contract.IMessageCenterContract.IMessageCenterModel;
import com.cbgolf.oa.entity.MessageBean;
import com.cbgolf.oa.event.EventMsg;
import com.cbgolf.oa.manager.DataManager;
import com.cbgolf.oa.net.NetCallBack;
import com.cbgolf.oa.net.Web;
import com.cbgolf.oa.net.WebAPI;
import java.util.Map;
import org.greenrobot.eventbus.EventBus;

/**
 * @author lq
 */
public class MessageCenterModelImp extends BaseModel implements IMessageCenterModel {

  @Override
  public void requestData(int requestType) {
    Map<String, String> map = new ArrayMap<>();
    map.put("pageSize", pageSize + "");
    map.put("messageType", "");
    map.put("currentPage", String.valueOf(requestType == LOADMORE ? ++page : 0));
    Web.getOK(WebAPI.message_all_get, map, new NetCallBack(response -> {
      EventBus.getDefault().post(new EventMsg.Builder()
          .setTarget(DataManager.MESSAGE_ALL_LIST)
          .setListMsg(getList(response, MessageBean.class, requestType))
          .setRequestType(requestType)
          .setError(errorMsg, errorCode)
          .build());

    }));
  }

  @Override
  public void readMsg(String id) {
    Web.getOK(WebAPI.message_details_get + id, new NetCallBack(response -> {

    }));
  }
}
